#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <mutex>
#include <condition_variable>
#include <thread>
#include <functional>
#include <memory>
#include <cassert>
#include <cstring>
#include <cerrno>
#include <unistd.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/epoll.h>
#include <sys/timerfd.h>
#include <sys/eventfd.h>

#define LOG(format, ...) {\
    time_t t = time(NULL);\
    struct tm *m = localtime(&t);\
    char *ts = asctime(m);\
    ts[strlen(ts) - 1] = '\0';\
    fprintf(stdout, "[%s:%d %s %p] " format "\n", __FILE__, __LINE__, ts, pthread_self(), ##__VA_ARGS__);\
}
#define DEFAULT_BUFFER_SIZE 4096
#define MAX_LISTEN 1024
#define MAX_EPOLLEVENTS 1024
#define DEFAULT_TIMEOUT 30

class Buffer;
class Socket;
class Channel;
class Connection;
class EventLoop;
class Poller;
class TimerQueue;

using ConnectionPtr = std::shared_ptr<Connection>;
using ConnectionComplateCallback = std::function<void(const ConnectionPtr&)>;
using ConnectionMsgCallback = std::function<void(const ConnectionPtr&, Buffer *)>;
using ConnectionCloseCallback = std::function<void(const ConnectionPtr&)>;
using OnTimerCallback = std::function<void()>;